#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define FNAME "/tmp/out"
#define BUFSIZE 1024

int main(){
    struct tm *tm;
    FILE *fp;
    int count;

    char buf[BUFSIZE];
    time_t stamp;

    fp = fopen(FNAME,"a+");

    while(fgets(buf,BUFSIZE,fp) != NULL)
        count++;
    
    while(1){
        stamp = time(&stamp);
        tm = localtime(&stamp);
        fprintf(fp, "%-4d%d-%d-%d-%d %d:%d:%d\n",++count,
        tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
        fflush(fp);
        sleep(1);
     }
     
    fclose(fp);

    exit(0);
}
